package no.capgemini.jzinema.test.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import no.capgemini.jzinema.data.MovieReader;
import no.capgemini.jzinema.data.XmlParser;
import no.capgemini.jzinema.domain.Cinema;
import no.capgemini.jzinema.domain.Movie;
import no.capgemini.jzinema.domain.Show;
import no.capgemini.jzinema.test.R;
import no.capgemini.jzinema.test.R.xml;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;

public class MovieLocalXmlReader implements MovieReader {
	private Map<String, Integer> movieFileMap;
	private Resources resources;

	public MovieLocalXmlReader(Resources resources) {
		this.resources =resources;
		movieFileMap = new HashMap<String, Integer>();
		movieFileMap.put("movies", R.xml.movies);
		movieFileMap.put("cinemas", R.xml.cinemas);
		movieFileMap.put("SFN20100036", R.xml.sfn20100036);
		movieFileMap.put("UIP20100129", R.xml.uip20100129);
		movieFileMap.put("NOR20090466", R.xml.nor20090466);
		movieFileMap.put("NOR20090463", R.xml.nor20090463);
		movieFileMap.put("SFN20100245", R.xml.sfn20100245);
		movieFileMap.put("FOX20100013", R.xml.fox20100013);
		movieFileMap.put("FOX20100079", R.xml.fox20100079);
		movieFileMap.put("ART20090538", R.xml.art20090538);
		movieFileMap.put("ART20091074", R.xml.art20091074);
		movieFileMap.put("FOX20100193", R.xml.fox20100193);
		movieFileMap.put("SMN20091053", R.xml.smn20091053);
		movieFileMap.put("UIP20080349", R.xml.uip20080349);
		movieFileMap.put("SMN20100469", R.xml.smn20100469);
		movieFileMap.put("SMN20090695", R.xml.smn20090695);
		movieFileMap.put("ART20091074", R.xml.art20091074);
		movieFileMap.put("ORO20100048", R.xml.oro20100048);
		movieFileMap.put("SBX20100238", R.xml.sbx20100238);
		movieFileMap.put("BVI20090474", R.xml.bvi20090474);
		movieFileMap.put("BVI20091088", R.xml.bvi20091088);
		movieFileMap.put("NOR20090320", R.xml.nor20090320);
		movieFileMap.put("BVI20100484", R.xml.bvi20100484);
		movieFileMap.put("BVI20091087", R.xml.bvi20091087);
		movieFileMap.put("BVI20091087", R.xml.bvi20091087);


	}

	public List<Cinema> readCinemas() {
		int id = movieFileMap.get("cinemas");
		XmlResourceParser xpp = resources.getXml(id);
		return XmlParser.readCinemas(xpp);
	}

	public Map<String, Movie> readMovies(Map<String, Movie> existingMovies,
			String... moviesToRead) {
		if (moviesToRead != null) {
			for (String string : moviesToRead) {
				int id = movieFileMap.get(string);
				System.out.println("id "+id);
				XmlResourceParser xpp = resources.getXml(id);
				existingMovies = XmlParser.readMovies(xpp, existingMovies);
				System.out.println("Size: "+existingMovies.size());
			}
		}
		return existingMovies;
	}

	public Map<String, Movie> readMovies(String... cinemasToReadFrom) {
		int id = movieFileMap.get("movies");
		XmlResourceParser xpp = resources.getXml(id);
		return XmlParser.readMovies(xpp, null);
	}

	public List<Show> readShowTimes(String movieId, String date, String... cinemaIds) {
		Show dummyShow1 = new Show();
		dummyShow1.setTheatre("Colosseum");
		dummyShow1.setStart("08.09.2010 18:30");
		dummyShow1.setLink("http://www.filmweb.no/");

		Show dummyShow2 = new Show();
		dummyShow2.setTheatre("Klingenberg");
		dummyShow2.setStart("08.09.2010 21:30");
		dummyShow2.setLink("http://www.filmweb.no/");
		
		List<Show> placeHolderList = new ArrayList<Show>();
		placeHolderList.add(dummyShow1);
		placeHolderList.add(dummyShow2);
		return placeHolderList;
	}

	
	
}
